package com.woniu.apartment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.woniu.apartment.vo.RoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.woniu.apartment.domain.Room;
import com.woniu.apartment.service.IRoomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房间Controller
 *
 * @author yy
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/apartment/tbroom")
@Api("房间管理")
public class RoomController extends BaseController {
    @Autowired
    private IRoomService roomService;

    /**
     * 查询房间列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbroom:list')")
    @GetMapping("/list")
    @ApiOperation("房间分页查询")
    public TableDataInfo list(Room room) {
        startPage();
        List<Room> list = roomService.selectRoomList(room);
        return getDataTable(list);
    }

    /**
     * 导出房间列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbroom:export')")
    @Log(title = "房间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("房间导出")
    public void export(HttpServletResponse response, Room room) {
        List<Room> list = roomService.selectRoomList(room);
        ExcelUtil<Room> util = new ExcelUtil<Room>(Room.class);
        util.exportExcel(response, list, "房间数据");
    }

    /**
     * 获取房间详细信息
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbroom:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("根据主键查询房间")
    @ApiImplicitParam(name = "ids", value = "用户ID", required = true, dataType = "Long")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(roomService.selectRoomById(id));
    }

    /**
     * 新增房间
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbroom:add')")
    @Log(title = "房间", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加房间")
    public AjaxResult add(@RequestBody Room room) {
        return toAjax(roomService.insertRoom(room));
    }

    /**
     * 修改房间
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbroom:edit')")
    @Log(title = "房间", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("更新房间")
    public AjaxResult edit(@RequestBody Room room) {
        return toAjax(roomService.updateRoom(room));
    }

    /**
     * 删除房间
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbroom:remove')")
    @Log(title = "房间", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除房间")
    @ApiImplicitParam(name = "ids", value = "主键数组", required = true, dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(roomService.deleteRoomByIds(ids));
    }

    @GetMapping("/orderRoom")
    public AjaxResult orderRoom(Integer apartmentId) {
        List<RoomVo> roomVoList = roomService.queryRoomByApartmentId(apartmentId);
          return AjaxResult.success(roomVoList);
    }
}
